package com.mxl.springsession.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author MXL
 * @date 2021/9/21 0021
 **/

@RestController
@RequestMapping("/session")
public class TestSpringSessionController {

    @RequestMapping("/setSession")
    public Object setSession(String username, HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("username", username);
        return "";
    }

    @RequestMapping("/getSession")
    public Object getSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        String username = session.getAttribute("username").toString();
        return "username: " + username;
    }


}
